<?php 
	include('function/connection.php');
	$cus_id = $cus_name = $cus_address = $cus_contact1 = $cus_contact2 = "";
	$action ="insert";
	$btn = "Save";
	
	// Select customer info
	if(isset($_GET['id'])){
		$querySelectCustomer = "SELECT * FROM tbl_customers WHERE id= $_GET[id]";
		$result = mysql_query($querySelectCustomer);
		$rowCustomer = mysql_fetch_array($result);
			$cus_id = $rowCustomer['cus_id'];
			$cus_name = $rowCustomer['cus_name'];
			$cus_address = $rowCustomer['cus_address'];
			$cus_contact1 = $rowCustomer['cus_contact1'];
			$cus_contact2 = $rowCustomer['cus_contact2'];
			
			$action = "update&id=".$_GET['id'];		
			$btn = "Update";
			
	}
	if(!isset($_GET['id'])){
		//max id
		$auto_id=maxOfAll("id","tbl_customers");
		$auto_id=$auto_id +1;
		$cus_id="C".$auto_id;
	}
?>
<form action="verify_customer.php?action=<?php echo $action ?>" method="post" enctype="multipart/form-data" class="form" name="form1" id="form1">
	<table  width="770">
        <thead>
            <tr>
                <th>Please insert your customer information:<br /><span class="red">* require feild</span></th>
            </tr>
        </thead>
         <tr>
    		<?php 
			if(@$errors!=""){
				echo " <td ><span class='red'>". @$errors."</span></td>";
			}else{
				if(isset($_REQUEST['msgStatus']))
					echo " <td ><span class='red'>". $_REQUEST['msgStatus']."</span></td>";
			 }
			?>
    	</tr>
	</table>
    <table class="bordered" width="770">
		<tr>
			<td colspan="2">
            	<label><span class="red">*</span> Customer ID:</label>
				<input type="text" class="txtID" name="txtCusID" value="<?php echo $cus_id;?>" readonly="readonly" /> </td>           
            <td colspan="2">
            	<label><span class="red">*</span> Customer Name:</label>
            	<input type="text" class="input req-min" minlength="1" style="width:200px; height:30px;" name="txtCusName" value="<?php echo $cus_name ?>" /> 
            </td>
		</tr>
        <tr>
        	<td colspan="4">
            	<label>Address:</label>
				<input type="text" class="txtCusAddress" name="txtCusAddress" value="<?php echo $cus_address ?>" />
           	</td>
		</tr>
        <tr>
			<td colspan="2">
            	<label>Contact1:</label>
				<input type="text" class="input req-min" minlength="1" style="width:200px; height:30px;" name="txtCusContact1" value="<?php echo $cus_contact1 ?>" />
            </td>
            <td colspan="2">
            	<label>Contact2:</label>
            	<input type="text" class="txtCusContact2" name="txtCusContact2" value="<?php echo $cus_contact2 ?>" />
            </td>
		</tr>
		<tr>
			<td colspan="4"><input type="submit" class="btnSubmit" name="Submit" id="Submit" value="<?php echo $btn ?>" />&nbsp;  
            <input type="button" class="btnSubmit" name="btncancel" value="Cancel" onclick="redirect('index.php?page=customer_list&action=customer_list')" />
            </td>
		</tr>
	</table>
</form>